package com.yiguantong.police.qrCode;


import android.os.Bundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * 
 */
public class BisDealUtil {
    public static Bundle obtainBundle(String url) {
        Pattern pattern = Pattern.compile("[a-z]+=\\d+");
        Matcher matcher = pattern.matcher(url);
        int count = 0;
        Bundle bundle = new Bundle();
        while (matcher.find()) {
            String group = matcher.group();
            int index = group.indexOf("=");
            if (index == -1)
                return null; // url结构不合法
            if (count % 2 == 0) {
                // 获取key value
                String key = group.substring(0, index);
                String value = group.substring(index + 1, group.length());
                bundle.putString(key, value);
            }
        }
        if (bundle.isEmpty())
            return null;

        return bundle;
    }

    public static String obtainClsName(String url) {
        int index = url.lastIndexOf("?");
        if (index != -1) {
            String clsName = url.substring(0, index);
            return clsName;
        }
        return url;
    }

    public static String obtainUrlClsName(String url) {
        int index = url.lastIndexOf("&");
        if (index != -1) {
            String clsName = url.substring(0, index);
            return clsName;
        }
        return url;
    }
    
    public static String obtainValueName(String url) {

        int index = url.lastIndexOf("=");
        if (index != -1) {
            String clsName = url.substring(index + 1);
            return clsName;
        }
        return null;
    }

    /**
     *
     */
    public static String subStringUrl(String url){
        int index = url.lastIndexOf("Android");
        if (index != -1) {
            String newUrl = url.substring(0, index);
            return newUrl;
        }
        return url;
    }

}
